<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head></h:head>

<h:body>
	<h:form id="form">
		<p:commandButton action="#{logoutBean.logout()}" value="Logout" />
		<h3>
			<p:outputLabel style="color: red" autoUpdate="true"
				value="#{eHomeBean.error}" />
		</h3>
	</h:form>
	<p:panelGrid columns="2">

		<h:form id="tpForm">
			<p:panel style="width: 100%" header="Search travel package">
				<p:outputLabel value="Travel package destination: " for="TPLocation" />
				<p:selectOneMenu id="TPLocation" value="#{eHomeBean.TPLocation}"
					converter="locationConverter">
					<p:ajax event="change" update=":tpForm"
						listener="#{eHomeBean.searchTP()}" />
					<f:selectItem itemLabel="Select One" itemValue="" />
					<f:selectItems value="#{applicationDataBean.locations}" var="l"
						itemLabel="#{l.name}" itemValue="#{l}" />
				</p:selectOneMenu>
				<p:message for="TPLocation" />

				<p:dataTable rendered="#{not empty eHomeBean.availableTPs}" id="TPs"
					var="TP" value="#{eHomeBean.availableTPs}"
					selection="#{eHomeBean.selectedTP}" selectionMode="single"
					rowKey="#{TP.TPId}">
					<f:facet name="header">  
            	Click "View" button after selecting a package to see details  
        		</f:facet>
					<p:column headerText="Travel package">
	    			#{TP.name}
	    		</p:column>
					<p:column headerText="Transport mean">
	    			#{TP.mean.name}
	    		</p:column>
					<p:column headerText="Hotel">
	    			#{TP.hotel.name}
	    		</p:column>
					<p:column headerText="Number of excursion">
	    			#{TP.excursions.size()}
	    		</p:column>
					<p:column style="width:4%">
						<p:commandButton action="#{eHomeBean.deleteTP()}" id="deleteTP"
							render=":tpForm" update=":tpForm" icon="ui-icon-circle-close"
							title="Delete">
							<f:setPropertyActionListener value="#{TP}"
								target="#{eHomeBean.selectedTP}" />
						</p:commandButton>
					</p:column>
					<f:facet name="footer">
						<p:commandButton update=":tpForm" id="viewButton" value="View"
							icon="ui-icon-search" action="#{eHomeBean.modifyTP()}" />
					</f:facet>
				</p:dataTable>

				<f:facet name="footer">
					<p:commandButton update="tpForm" action="#{eHomeBean.createTP()}"
						value="Add travel package" />
				</f:facet>
			</p:panel>
		</h:form>


		<h:form id="productForm">
			<p:panel style="width: 100%" header="Search product">
				<p:outputLabel value="Product location: " for="productLocation" />
				<p:selectOneMenu id="productLocation"
					value="#{eHomeBean.productLocation}" converter="locationConverter">
					<p:ajax event="change" update=":productForm"
						listener="#{eHomeBean.searchProducts()}" />
					<f:selectItem itemLabel="Select One" itemValue="" />
					<f:selectItems value="#{applicationDataBean.locations}" var="l"
						itemLabel="#{l.name}" itemValue="#{l}" />
				</p:selectOneMenu>
				<p:message for="productLocation" />

				<p:dataTable rendered="#{not empty eHomeBean.availableProducts}"
					id="products" var="p" value="#{eHomeBean.availableProducts}"
					selection="#{eHomeBean.selectedProduct}" selectionMode="single"
					rowKey="#{p.productId}">
					<f:facet name="header">  
            	Click "View" button after selecting a package to see details  
        		</f:facet>
					<p:column headerText="Product name">
	    			#{p.name}
	    		</p:column>
					<p:column headerText="Product type">
	    			#{p.productType.name}
	    		</p:column>
					<f:facet name="footer">
						<p:commandButton update=":productForm" id="viewButton"
							value="View" icon="ui-icon-search"
							action="#{eHomeBean.modifyProduct()}" />
					</f:facet>
				</p:dataTable>
			</p:panel>
		</h:form>

	</p:panelGrid>

	<p:panelGrid columns="3" cellpadding="0">
		<h:form id="meanForm">
			<p:panelGrid cellpadding="5" columns="3" id="meanPanel"
				style="height: 100%">
				<f:facet name="header">
					<p:outputLabel value="Add transport mean" />
				</f:facet>

				<p:outputLabel value="name: " for="nameMChoice" />
				<p:inputText id="nameMChoice" value="#{eHomeBean.insertedMean.name}"
					size="25" />
				<p:message for="nameMChoice" />

				<p:outputLabel value="type: " for="typeChoice" />
				<p:selectOneMenu id="typeChoice"
					value="#{eHomeBean.insertedMean.meanType}">
					<f:selectItem itemLabel="Select One" itemValue="" />
					<f:selectItems value="#{applicationDataBean.meanTypes}" var="m"
						itemValue="#{m}" />
				</p:selectOneMenu>
				<p:message for="typeChoice" />

				<p:outputLabel value="destination: " for="destinationChoice" />
				<p:selectOneMenu id="destinationChoice"
					value="#{eHomeBean.insertedMean.location}"
					converter="locationConverter">
					<f:selectItem itemLabel="Select One" itemValue="" />
					<f:selectItems value="#{applicationDataBean.locations}" var="l"
						itemLabel="#{l.name}" itemValue="#{l}" />
				</p:selectOneMenu>
				<p:message for="destinationChoice" autoUpdate="true" />

				<p:outputLabel value="departure: " for="departureChoice" />
				<p:selectOneMenu id="departureChoice"
					value="#{eHomeBean.insertedMean.departure}"
					converter="departureConverter">
					<f:selectItem itemLabel="Select One" itemValue="" />
					<f:selectItems value="#{applicationDataBean.departures}" var="d"
						itemLabel="#{d.name}" itemValue="#{d}" />
				</p:selectOneMenu>
				<p:message for="departureChoice" />

				<p:outputLabel value="space: " for="spaceSelection" />
				<p:spinner id="spaceSelection"
					value="#{eHomeBean.insertedMean.spaces}" min="0" max="100" />
				<p:message for="spaceSelection" />

				<p:outputLabel value="price (round trip): " for="priceMSelection" />
				<p:inputText id="priceMSelection"
					value="#{eHomeBean.insertedMean.price}">€
					<f:validator validatorId="numberValidator" />
				</p:inputText>
				<p:message for="priceMSelection" autoUpdate="true" />

				<f:facet name="footer">
					<p:commandButton value="Insert" action="#{eHomeBean.saveMean()}"
						update="meanPanel :form" />
				</f:facet>
			</p:panelGrid>
		</h:form>

		<h:form id="hotelForm">
			<p:contextMenu for="rooms" widgetVar="cMenu">
				<p:menuitem value="Edit Cell" icon="ui-icon-search"
					onclick="PF('roomsTable').showCellEditor();return false;" />
				<p:menuitem value="Hide Menu" icon="ui-icon-close"
					onclick="PF('cMenu').hide()" />
			</p:contextMenu>
			<p:panelGrid id="hotelPanel" style="height: 100%">
				<f:facet name="header">
					<p:row>
						<p:column colspan="3">
							<p:outputLabel value="Add hotel" />
						</p:column>
					</p:row>
				</f:facet>
				<p:row>
					<p:column>
						<p:outputLabel value="name: " for="nameHChoice" />
					</p:column>
					<p:column>
						<p:inputText id="nameHChoice"
							value="#{eHomeBean.insertedHotel.name}" size="25" />
					</p:column>
					<p:column>
						<p:message for="nameHChoice" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<p:outputLabel value="location: " for="locationHChoice" />
					</p:column>
					<p:column>
						<p:selectOneMenu id="locationHChoice"
							value="#{eHomeBean.insertedHotel.location}"
							converter="locationConverter">
							<f:selectItem itemLabel="Select One" itemValue="" />
							<f:selectItems value="#{applicationDataBean.locations}" var="l"
								itemLabel="#{l.name}" itemValue="#{l}" />
						</p:selectOneMenu>
					</p:column>
					<p:column>
						<p:message for="locationHChoice" />
					</p:column>
				</p:row>
				<p:row>
					<p:column colspan="2">
						<p:dataTable id="rooms" var="r" value="#{eHomeBean.insertedRooms}"
							editable="true" editMode="cell" widgetVar="roomsTable">

							<p:column headerText="Room type">
								<p:outputLabel value="#{r.type.toString()}" />
							</p:column>

							<p:column headerText="Number">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{r.totalRooms}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText id="nInput" value="#{r.totalRooms}"
											style="width:96%" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="Price">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{r.price}" prefix="€" />
									</f:facet>
									<f:facet name="input">
										<p:inputText id="priceInput" value="#{r.price}"
											style="width:96%" />€
									</f:facet>
								</p:cellEditor>
							</p:column>

						</p:dataTable>
					</p:column>
					<p:column>
						<p:message for="rooms" />
					</p:column>
				</p:row>
				<f:facet name="footer">
					<p:row>
						<p:column colspan="3">
							<p:commandButton value="Insert" action="#{eHomeBean.saveHotel()}"
								update="hotelPanel :form" />
						</p:column>
					</p:row>
				</f:facet>
			</p:panelGrid>
		</h:form>

		<h:form id="excursionForm">
			<p:panelGrid columns="3" id="excursionPanel" style="height: 100%">
				<f:facet name="header">
					<p:outputLabel value="Add excursion" />
				</f:facet>
				<p:outputLabel value="name: " for="nameEChoice" />
				<p:inputText id="nameEChoice"
					value="#{eHomeBean.insertedExcursion.name}" size="25" />
				<p:message for="nameEChoice" />

				<p:outputLabel value="location: " for="locationEChoice" />
				<p:selectOneMenu id="locationEChoice"
					value="#{eHomeBean.insertedExcursion.location}"
					converter="locationConverter">
					<f:selectItem itemLabel="Select One" itemValue="" />
					<f:selectItems value="#{applicationDataBean.locations}" var="l"
						itemLabel="#{l.name}" itemValue="#{l}" />
				</p:selectOneMenu>
				<p:message for="locationEChoice" />

				<p:outputLabel value="duration (days): " for="durationSelection" />
				<p:spinner id="durationSelection"
					value="#{eHomeBean.insertedExcursion.duration}" min="1" max="100" />
				<p:message for="durationSelection" />

				<p:outputLabel value="price: " for="priceESelection" />
				<p:inputText id="priceESelection"
					value="#{eHomeBean.insertedExcursion.price}">€
					<f:validator validatorId="numberValidator" />
				</p:inputText>
				<p:message for="priceESelection" />

				<p:outputLabel value="Starting at: " for="weekDay" />
				<p:selectOneMenu id="weekDay"
					value="#{eHomeBean.insertedExcursion.weekDay}">
					<f:selectItems value="#{applicationDataBean.weekDays}" />
				</p:selectOneMenu>
				<p:message for="weekDay" />

				<f:facet name="footer">
					<p:commandButton value="Insert"
						action="#{eHomeBean.saveExcursion()}"
						update="excursionPanel :form" />
				</f:facet>
			</p:panelGrid>
		</h:form>
	</p:panelGrid>
</h:body>
</html>